const BASE_URL = 'http://localhost:8080/wxdemo'

const request = (url, method, data) => {
    return new Promise((resolve, reject) => {
        wx.request({
            url: BASE_URL + url,
            method,
            data,
            header: {
                'Content-Type': 'application/json',
            },
            success: res => {
                if (res.statusCode >= 200 && res.statusCode < 300) {
                    resolve(res)
                } else {
                    reject(res)
                }
            },
            fail: reject
        })
    })
}

module.exports = {
    peopelPage(page = 0, size = 10, searchName = '') {
        return request('/peopel/page', 'GET', {
            current: page,
            size: size,
            name: searchName
        })
    },

    peopelAdd(data) {
        return request('/peopel', 'POST', data)
    },

    peopelUpdate(data) {
        return request(`/peopel/`, 'PUT', data)
    },

    peopelDelete(id) {
        return request(`/peopel/${id}`, 'DELETE')
    },

    getSexCharData(id) {
        return request(`/peopel/getSexChartData`, 'GET')
    }
}